package com.devhelper.examples.gef.part;

import java.beans.PropertyChangeEvent;
import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;

import com.devhelper.examples.gef.figure.EnterpriseFigure;
import com.devhelper.examples.gef.model.Enterprise;
import com.devhelper.examples.gef.model.Node;
import com.devhelper.examples.gef.policy.ExEditLayoutPolicy;

public class EnterpriseEditPart extends ExAbstractEditPart {

    @Override
    protected IFigure createFigure() {
        return new EnterpriseFigure();
    }

    @Override
    protected void createEditPolicies() {
        installEditPolicy(EditPolicy.LAYOUT_ROLE, new ExEditLayoutPolicy());

    }

    @Override
    protected void refreshVisuals() {
        EnterpriseFigure figure = (EnterpriseFigure) getFigure();
        Enterprise model = (Enterprise) getModel();

        figure.setName(model.getName());
        figure.setAddress(model.getAddress());
    }

    @Override
    public List<Node> getModelChildren() {
        return ((Enterprise) getModel()).getChildren();
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName().equals(Node.PROPERTY_LAYOUT)) {
            refreshVisuals();
        }
    }
}
